<?php
class isp_customer_model extends MY_Model {
	var $model = 'isp_customer';

	function getApp() {
		$ls_sql	= "	SELECT	JENIS value,
							JENIS display
					FROM	ADMIN_PRIMKOKAS.ISP_PRODUK
					ORDER BY JENIS";
					
		$result	= $this->db->query($ls_sql);
		if($result->num_rows() > 0){
			return $result->result_array();
		}else{
			return array();
		}
	}
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT	id_customer,kode_customer,nama,no_id,jabatan,nama_perusahaan,alamat,kota,kode_pos,no_telp,no_hp,no_hp2,no_fax,email,status,
							TO_CHAR(tgl_survey,'DD/MM/YYYY') tgl_survey,
							TO_CHAR(tgl_instalasi,'DD/MM/YYYY') tgl_instalasi,
							tgl_trial,
							TO_CHAR(tgl_aktifasi,'DD/MM/YYYY') tgl_aktifasi,
							TO_CHAR(tgl_berakhir,'DD/MM/YYYY') tgl_berakhir,
							TO_CHAR(tgl_berhenti_trial,'DD/MM/YYYY') tgl_berhenti_trial
					FROM	ISP_CUSTOMER
					WHERE	lower(status) = lower('Berlangganan') AND (UPPER(id_customer) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kode_customer) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'id_customer' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order') );
					
		return json_encode( $this->paging($ls_sql) );
	}

	function GetJSON3()
	{
		$ls_sql1	= "	SELECT	id_customer,kode_customer,nama,no_id,jabatan,nama_perusahaan,alamat,kota,kode_pos,no_telp,no_hp,no_hp2,no_fax,email,status,
							TO_CHAR(tgl_survey,'DD/MM/YYYY') tgl_survey,
							TO_CHAR(tgl_instalasi,'DD/MM/YYYY') tgl_instalasi,
							tgl_trial,
							TO_CHAR(tgl_aktifasi,'DD/MM/YYYY') tgl_aktifasi,
							TO_CHAR(tgl_berakhir,'DD/MM/YYYY') tgl_berakhir,
							TO_CHAR(tgl_berhenti_trial,'DD/MM/YYYY') tgl_berhenti_trial
					FROM	ISP_CUSTOMER
					WHERE	lower(status) = lower('Trial') AND (UPPER(id_customer) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'id_customer' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order') );
					
		return json_encode( $this->paging($ls_sql1) );
	}

	function GetJSON4()
	{
		$ls_sql	= "	SELECT	id_customer,kode_customer,nama,no_id,jabatan,nama_perusahaan,alamat,kota,kode_pos,no_telp,no_hp,no_hp2,no_fax,email,status,
							TO_CHAR(tgl_survey,'DD/MM/YYYY') tgl_survey,
							TO_CHAR(tgl_instalasi,'DD/MM/YYYY') tgl_instalasi,
							tgl_trial,
							TO_CHAR(tgl_aktifasi,'DD/MM/YYYY') tgl_aktifasi,
							TO_CHAR(tgl_berakhir,'DD/MM/YYYY') tgl_berakhir,
							TO_CHAR(tgl_berhenti_trial,'DD/MM/YYYY') tgl_berhenti_trial
					FROM	ISP_CUSTOMER
					WHERE	lower(status) = lower('Tidak Berlangganan') AND (UPPER(id_customer) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'id_customer' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order') );
					
		return json_encode( $this->paging($ls_sql) );
	}
		
	function Add($arr_data){
		$this->db->insert('isp_customer', $arr_data);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('isp_customer', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_id_customer){
		$result = $this->db->get_where('isp_customer', array('id_customer' => $as_id_customer));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_id_customer)
	{
		$result = $this->db->get_where('isp_customer', array('id_customer' => $as_id_customer));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			if(	intval($this->get_data("SELECT COUNT(1) FROM isp_customer WHERE id_customer = '".$arr_rule['id_customer']."'"))<=0)
			{
				return $this->error_delete.' [id: '.$arr_rule['id_customer']."]<br />";
			}else{
				$this->db->delete('isp_customer', array('id_customer' => $arr_rule['id_customer']));
				return '';
			}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}

?>